﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows;

using MySql.Data.MySqlClient;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

        protected void Button1_Click1(object sender, EventArgs e)
        {

        }

        protected void Button1_Click2(object sender, EventArgs e)
        {
            string userName = this.TextBox1.Text;
            string userPassword = this.TextBox2.Text;
            if (userName.Equals("") || userPassword.Equals(""))
            {
                MessageBox.Show("用户名或密码不能为空！");
            }
            else
            {
                string connectstring = "data source=121.43.119.97;user id=root;password=h666niub;database=ticket_management_system;pooling=true;charset=utf8;";
                //定义与数据连接的链接
                MySqlConnection connection = new MySqlConnection(connectstring);
                //打开这个链接
                connection.Open();
                try
                {
                    string sql = "select count(*) from user where userName= '" + userName + "' and password = '" + userPassword + "'";
                    MySqlCommand com = new MySqlCommand(sql, connection);
                    if (Convert.ToInt32(com.ExecuteScalar()) > 0)
                    {
                        MessageBox.Show("登录成功！");

                        
                        Response.Redirect("scenicspot.aspx",false);

                    }
                     connection.Close();
                   
            
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString() + "打开数据库失败");
                }

            }

        }
    }
}